package com.cuit.controller;

import com.cuit.pojo.Patient;
import com.cuit.service.Impl.PatientServiceImpl;
import com.cuit.service.PatientService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class PatientLoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String p_id = req.getParameter("p_id");
        String p_password = req.getParameter("p_password");
        Patient patient = new Patient(p_id,p_password);
        PatientService patientService =new PatientServiceImpl();
        if(patientService.login(patient)==null){
            System.out.println("手机号或密码错误，请重新输入！！！");
            req.getSession().setAttribute("message","手机号或密码错误，请重新输入！！！");
            resp.sendRedirect("patient/login.jsp");
        }else{
            Patient patient1 = patientService.login(patient);
            req.getSession().setAttribute("patient",patient1);
            req.getSession().setAttribute("message","");
            resp.sendRedirect("patient/personal_center2.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
